package 每日一题;

/**
 * @author 会玩的洋洋
 * https://leetcode-cn.com/problems/maximum-number-of-balloons/
 */
public class _1189_气球的最大数量 {
    /**
     * 统计各个字母的数量  获取最小值即可
     * @param text 目标字符串
     * @return int
     */
    public int maxNumberOfBalloons(String text) {
        int len = text.length();
        int b = 0, a = 0, l = 0, o = 0, n = 0;
        for (int i = 0; i < len; i++) {
            char c = text.charAt(i);
            switch (c) {
                case 'b':
                    b++;
                    break;
                case 'a':
                    a++;
                    break;
                case 'l':
                    l++;
                    break;
                case 'o':
                    o++;
                    break;
                case 'n':
                    n++;
                    break;
                default:
                    break;
            }
        }
        return Math.min(Math.min(Math.min(Math.min(b, a), l >> 1), o >> 1), n);
    }
}
